﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Boolean a = true;
            while (a)
            {
                Console.WriteLine();
                Console.WriteLine("1.录入成绩 2.银行 3.退出");
                int key = int.Parse(Console.ReadLine());
                switch (key)
                {
                    case 1:
                        Test01();
                        break;
                    case 2:
                        Test02();
                        break;
                    case 3:
                        a = false;
                        break;
                    default:
                        Console.WriteLine("输入错误，请重新输入");
                        break;
                }
            }
        }
        public static void Test01()
        {
            Console.WriteLine("请输入学生数");
            int a = int.Parse(Console.ReadLine());
            float[] arr = new float[a];
            Boolean b = false;
            for (int i = 0; i < arr.Length; i++)
            {
                b = false;
                try
                {
                    Console.WriteLine("请输入第{0}个学生的成绩", (i + 1));
                    arr[i] = float.Parse(Console.ReadLine());
                }
                catch (FormatException e)
                {
                    Console.WriteLine(e.Message);
                    Console.WriteLine(e.Source);
                    Console.WriteLine(e.StackTrace);
                    b = true;
                }
                catch (OverflowException e)
                {
                    Console.WriteLine(e.Message);
                    Console.WriteLine(e.Source);
                    Console.WriteLine(e.StackTrace);
                    b = true;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Console.WriteLine(e.Source);
                    Console.WriteLine(e.StackTrace);
                    b = true;
                }
                finally
                {
                    Console.WriteLine("第{0}个学生的成绩录完", (i + 1));
                    Console.WriteLine();
                }
                Boolean o = true;
                while (o)
                {
                    o = false;
                    if (b)
                    {
                        b = false;
                        try
                        {
                            Console.WriteLine();
                            Console.WriteLine("请输入重新第{0}个学生的成绩", (i + 1));
                            arr[i] = float.Parse(Console.ReadLine());
                        }
                        catch (FormatException e)
                        {
                            Console.WriteLine(e.Message);
                            Console.WriteLine(e.Source);
                            Console.WriteLine(e.StackTrace);
                            b = true;
                            o = true;
                        }
                        catch (OverflowException e)
                        {
                            Console.WriteLine(e.Message);
                            Console.WriteLine(e.Source);
                            Console.WriteLine(e.StackTrace);
                            b = true;
                            o = true;
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                            Console.WriteLine(e.Source);
                            Console.WriteLine(e.StackTrace);
                            b = true;
                            o = true;
                        }
                    }
                }

            }
            float sum = 0;
            for (int i = 0; i < arr.Length; i++)
            {
                sum += arr[i];
            }
            float age = sum / a;
            Console.WriteLine("总学生数为{0}，总分数为{1}，平均分为{2}", a, sum, age);
        }
        public static void Test02()
        {
            //存放在银行账户中的余额
            double a = 100000000.00;
            //用户想要从银行账户中提取的金额
            double b = 0;
            Boolean f = false;
            Boolean p = true;
            while (p)
            {
                Console.WriteLine("请选择功能：1、存款，2、取款 3、退出");
                int key = int.Parse(Console.ReadLine());
                switch (key)
                {
                    case 1:
                        Console.WriteLine("请输入存款的金额");
                        try
                        {
                            double c = double.Parse(Console.ReadLine());
                            a += c;
                        }
                        catch (FormatException e)
                        {
                            Console.WriteLine(e.Message);
                            Console.WriteLine(e.Source);
                            Console.WriteLine(e.StackTrace);
                            f = true;
                        }
                        Boolean o = true;
                        while (o)
                        {
                            o = false;
                            if (f)
                            {
                                f = false;
                                Console.WriteLine();
                                Console.WriteLine("请输入重新存款的金额");
                                try
                                {
                                    double c = double.Parse(Console.ReadLine());
                                    a += c;
                                }
                                catch (FormatException e)
                                {
                                    Console.WriteLine(e.Message);
                                    Console.WriteLine(e.Source);
                                    Console.WriteLine(e.StackTrace);
                                    f = true;
                                    o = true;
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(e.Message);
                                    Console.WriteLine(e.Source);
                                    Console.WriteLine(e.StackTrace);
                                    f = true;
                                    o = true;
                                }
                            }
                            else
                            {
                                Console.WriteLine("余额为{0}", a);
                            }
                        }


                        break;
                    case 2:
                        Console.WriteLine("请输入取款的金额");
                        try
                        {
                            b = double.Parse(Console.ReadLine());
                            if (b > a)
                            {
                                throw new ArgumentOutOfRangeException();
                            }
                        }
                        catch (OverflowException e)
                        {
                            Console.WriteLine(e.Message);
                            Console.WriteLine(e.Source);
                            Console.WriteLine(e.StackTrace);
                            f = true;
                        }
                        Boolean l = true;
                        while (l)
                        {
                            l = false;
                            if (f)
                            {
                                f = false;
                                Console.WriteLine();
                                Console.WriteLine("请重新输入取款的金额");
                                try
                                {
                                    b = double.Parse(Console.ReadLine());
                                    if (b > a)
                                    {
                                        throw new ArgumentOutOfRangeException();
                                    }
                                }
                                catch (OverflowException e)
                                {
                                    Console.WriteLine(e.Message);
                                    Console.WriteLine(e.Source);
                                    Console.WriteLine(e.StackTrace);
                                    f = true;
                                    l = true;
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(e.Message);
                                    Console.WriteLine(e.Source);
                                    Console.WriteLine(e.StackTrace);
                                    f = true;
                                    l = true;
                                }
                            }
                            else
                            {
                                a = a - b;
                                Console.WriteLine("余额为{0}", a);
                            }
                        }
                        break;
                    case 3:
                        p = false;
                        break;
                    default:
                        Console.WriteLine("输入错误，请重新输入");
                        break;
                }
            }
        }
    }
}
